%option noyywrap nodefault yylineno

%{
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "type.h"
#include "absyn.h"
#include "block.tab.h"
%}

EXP ([Ee][-+]?[0-9]+])

%%

"+" |
"-" |
"*" |
"/" |
"=" |
"{" |
"}" |
"(" |
")" |
"[" |
"]" |
"." |
"," |
";" { return yytext[0]; }

"int" {yylval.sym = lookupSymbol(yytext); 
        if(yylval.sym==NULL)
            yylval.sym = insertSymbol(yytext);
        return INT;
        }
"double" {yylval.sym = lookupSymbol(yytext); 
        if(yylval.sym==NULL)
            yylval.sym = insertSymbol(yytext);
        return DOUBLE;
        }
"void" {yylval.sym = lookupSymbol(yytext); 
        if(yylval.sym==NULL)
            yylval.sym = insertSymbol(yytext);
        return VOID;
        }
"char" {yylval.sym = lookupSymbol(yytext); 
        if(yylval.sym==NULL)
            yylval.sym = insertSymbol(yytext);
        return CHAR;
        }
"struct" { return STRUCT; }

"for"   { return FOR; }
"while" { return WHILE; }
"if" { return IF; }
"else" { return ELSE; }
"return" { return RETURN; }

"<"  { yylval.cmp = 0; return CMP; }
"<=" { yylval.cmp = 1; return CMP; }
"==" { yylval.cmp = 2; return CMP; }
">"  { yylval.cmp = 3; return CMP; }
">=" { yylval.cmp = 4; return CMP; }
"!=" { yylval.cmp = 5; return CMP; }

[a-zA-Z][a-zA-Z0-9]* { 
                yylval.sym = lookupSymbol(yytext); 
                if(yylval.sym==NULL)
                        yylval.sym = insertSymbol(yytext);
		return IDENTIFIER; 
        }

-?[0-9]+ {      
                yylval.sym = lookupSymbol(yytext); 
                if(yylval.sym==NULL)
                        yylval.sym = insertSymbol(yytext);
                return INTEGER; 
        }

-?[0-9]+"."[0-9]*{EXP}? |
"."?[0-9]+{EXP}? { 
                        yylval.sym = lookupSymbol(yytext); 
                        if(yylval.sym==NULL)
                                yylval.sym = insertSymbol(yytext); 
                        return FLOAT; 
                }

\'[A-Za-z0-9]\' {
                        yylval.sym = lookupSymbol(yytext); 
                        if(yylval.sym==NULL)
                                yylval.sym = insertSymbol(yytext); 
                        return CHAREACTER; 
                }

"//".*
[ \t]

\n { return EOL; }

. { yyerror("unknown character %c\n", *yytext); }

%%
